<?php
    header("Content-type:text/html;charset=utf-8");
    require('./conn/mysql.php');

    $status = $_GET['status'];

    try{
        if($_POST['type']== "payment"){
            $user_id = $_POST['user_id'];
            $order_no = $_POST['order_no'];
            //["未支付", "已支付", "待发货", "邮递中", "待收货", "已完成"];
            $sql = "update orders set status = '已支付' where user_id=$user_id and order_no in($order_no)";
            $res = mysql::query($sql);
            if(!$res) die(write(0, '支付失败!'));
            echo write(1, '支付成功!');
        }else{
            $sql = "select * from orders where status = '$status'";
            $res = mysql::getAll($sql);
            foreach($res as $index=>$obj){
                $sql1 = "select * from orders_detail o inner join goods g on g.goods_id = o.goods_id where o.order_id = ".$obj['order_id'];
                $res1 = mysql::getAll($sql1);
                $res[$index]['detail'] = $res1;
            }
            if(!$res) die(write(1, '无数据'));
            echo write(1, '获取成功', $res);
        }
    }catch(\Throwable $t){
        echo write(0, ''.$t);
    }finally{
         mysql::close();
    }
    function write($code, $msg, $data=[]){
        $rd = array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        );
        return json_encode($rd, JSON_UNESCAPED_UNICODE);
    }
?>